home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9950 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: isonews.bbn.hp.com!hpbblb!news
  2. From: Matthias Dittrich <matti>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Question about visibility of local variables
  5. Date: 5 Mar 1996 08:37:19 GMT
  6. Organization: Hewlett-Packard Co.
  7. Message-ID: <4hgufv$48h@hpbblb.bbn.hp.com>
  8. References: <4hfkpc$9em@guardian.forbin.com>
  9. NNTP-Posting-Host: trabant.bbn.hp.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
  14. X-URL: news:4hfkpc$9em@guardian.forbin.com
  15.  
  16. genesis@forbin.com (Dances with Demons) wrote:
  17. >.........
  18. >The question is:  When you define a variable in main(), and call another 
  19. >function, or even when defining a local variable in a function that calls 
  20. >another function, why are the local variables not destroyed.
  21. >   I had a thought that maybe since main() called the function, it still had 
  22. >control, (at least as far as variable usage went) and therefore didn't
  23. >free up the memory until the function is actually completed, (End
  24. >of the program), but I wasn't sure.  Could someone please verify that this is 
  25. >indeed the case, or refute it and give me the real reason.
  26. >...
  27. A variable defined in a block (you should do this at the begin) is valid
  28. till the end of the block.
  29.  
  30. Good luck,
  31. Matthias
  32.  
  33.